主题
发送粘贴命令 - SendPaste2
函数简介
向指定窗口发送 WM_PASTE 粘贴消息,触发目标控件自身的粘贴逻辑(内容来自系统剪贴板)。
适用于 Edit、RichEdit 等标准控件。若目标不处理 WM_PASTE,请改用 SendPaste 或 SendPaste3。
接口名称
SendPaste2DLL调用
int SendPaste2(long ola, long hwnd);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 目标窗口句柄。为 0 时使用当前 绑定窗口。建议指向可编辑控件本身。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.SetClipboard("要粘贴的文本");
int ret = ola.SendPaste2(hwnd);csharp
using OLAPlug;
var ola = new OLAPlugServer();
ola.SetClipboard("要粘贴的文本");
int ret = ola.SendPaste2(hwnd);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ola.SetClipboard("要粘贴的文本")
ret = ola.SendPaste2(hwnd)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.SetClipboard("要粘贴的文本");
int ret = ola.SendPaste2(hwnd);go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ola.SetClipboard("要粘贴的文本")
ret := ola.SendPaste2(hwnd)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
ola.set_clipboard("要粘贴的文本");
let ret = ola.send_paste2(&hwnd);cpp
var ola = com("OlaPlug.OlaSoft")
ola.SetClipboard("要粘贴的文本")
var ret = ola.SendPaste2(hwnd)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.SetClipboard "要粘贴的文本"
ret = ola.SendPaste2(hwnd)text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.SetClipboard (“要粘贴的文本”)
ret = ola.SendPaste2(hwnd)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.SetClipboard("要粘贴的文本");
var ret = ola.SendPaste2(hwnd);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.SetClipboard("要粘贴的文本")
整数 ret = ola.SendPaste2(hwnd)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.SetClipboard("要粘贴的文本");
int32_t ret = ola.SendPaste2(hwnd);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
SetClipboard(instance, "要粘贴的文本");
SendPaste2(instance, hwnd);csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetClipboard(long ola, string value);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SendPaste2(long ola, long hwnd);
long instance = CreateCOLAPlugInterFace();
SetClipboard(instance, "要粘贴的文本");
SendPaste2(instance, hwnd);python
from ctypes import CDLL, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SetClipboard(instance, "要粘贴的文本".encode("utf-8"))
ola.SendPaste2(instance, hwnd)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功投递消息。 |
0 | 失败(句柄无效等)。 |
注意事项
| 项目 | 说明 |
|---|---|
| 前置条件 | 通常需先 SetClipboard(或剪贴板已有文本)。 |
| 与 SendPaste | SendPaste 是读剪贴板后 逐字发送;本接口是 粘贴消息,速度更快、更接近用户手动粘贴。 |
| 句柄选择 | 应对准输入框 HWND;对顶层壳窗口发 WM_PASTE 可能无效。 |
